package pyrachnid.model;

import java.util.ArrayList;
import java.util.Collections;

import pyrachnid.model.robot_model.Manager;
import Event.Event;
import Event.Operation.Operation;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public abstract class ObservableWithEvent< T extends Operation> extends Observable {
	private ArrayList<Event> _event;
	private static Manager _manager;
	
	public ObservableWithEvent() {
		super();
		_manager = Manager.getInstance();
		_event = new ArrayList<Event>();
	}

	public ArrayList<Event> getEvent() {
		return _event;
	}
	
	public void addOperation(T p_operation){
		Event newEvent = new Event(p_operation,_manager.getIncTimer());
		_event.add(newEvent);
	}
	
	public String getSerializeEvent() {
		 String retourEvent = "";
		 Collections.sort(_event); // Trie par la date
		  XStream xstream = new XStream(new DomDriver());
		 if(_event.size()!=0){
			 retourEvent = xstream.toXML(_event);// S�rialisation de l'objet ArrayList Event
		 }
		 return retourEvent;
	}
}
